package hu.kisprof.quiz.model.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

public class GameQuestion implements Serializable{
	private static final long serialVersionUID = -553717604978894764L;
	private String question;
	private String gAnswer;
	private String wAnswer1;
	private String wAnswer2;
	private String wAnswer3;
	private int questionId;
	private int dif;
	
	
	public GameQuestion(int questionId, String question, String goodAnswer, List<String> s, int dif){
		this.question = question;
		this.gAnswer = goodAnswer;
		this.questionId = questionId;
		this.dif=dif;
		ArrayList<String> wrongAnswers = new ArrayList<String>(s);
		HashSet<String> set = new HashSet<String>();		
		while(set.size()<3){
			set.add(wrongAnswers.get(new Random().nextInt(wrongAnswers.size())));
		}
		Iterator<String> it = set.iterator();
		wAnswer1=it.next();
		wAnswer2=it.next();
		wAnswer3=it.next();
		
		
	}
	
	
	public GameQuestion(String question, String goodAnswer ,String wrongAnswer1, String wrongAnswer2, String... wa){
		this.question = question;
		this.gAnswer = goodAnswer;
		ArrayList<String> wrongAnswers = new ArrayList<String>();
		HashSet<String> set = new HashSet<String>();
		wrongAnswers.add(wrongAnswer1);
		wrongAnswers.add(wrongAnswer2);
		for(int i=0;i<wa.length;i++){
			wrongAnswers.add(wa[i]);
		}
		
		while(set.size()<3){
			set.add(wrongAnswers.get(new Random().nextInt(wrongAnswers.size())));
		}
		Iterator<String> it = set.iterator();
		wAnswer1=it.next();
		wAnswer2=it.next();
		wAnswer3=it.next();
		
		
	}
	
	
	public ArrayList<String> getAnswers(){
		ArrayList<String> answers = new ArrayList<String>();
		answers.add(gAnswer);
		answers.add(wAnswer1);
		answers.add(wAnswer2);
		answers.add(wAnswer3);
		for(int i=0;i<answers.size();i++){
			int j= new Random().nextInt(answers.size());
			String tmp = answers.get(i);
			answers.set(i,answers.get(j));
			answers.set(j,tmp);
		}
		return answers;

		
		
	}



	public String getQuestion() {
		return question;
	}




	public void setQuestion(String question) {
		this.question = question;
	}




	public String getgAnswer() {
		return gAnswer;
	}




	public void setgAnswer(String gAnswer) {
		this.gAnswer = gAnswer;
	}




	public String getwAnswer1() {
		return wAnswer1;
	}




	public void setwAnswer1(String wAnswer1) {
		this.wAnswer1 = wAnswer1;
	}




	public String getwAnswer2() {
		return wAnswer2;
	}




	public void setwAnswer2(String wAnswer2) {
		this.wAnswer2 = wAnswer2;
	}




	public String getwAnswer3() {
		return wAnswer3;
	}




	public void setwAnswer3(String wAnswer3) {
		this.wAnswer3 = wAnswer3;
	}


	public int getQuestionId() {
		return questionId;
	}


	public int getDif() {
		return dif;
	}


	public void setDif(int dif) {
		this.dif = dif;
	}
	
	
}
